//
//  XJWalletZFBView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/23.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJWalletZFBView.h"
@interface XJWalletZFBView()
@property(nonatomic, strong) UIView *bgView;
//没有数据的时候的界面
@property(nonatomic, strong) UIImageView *noDataIv;
@property(nonatomic, strong) UILabel *addZfbAccountLb; //添加支付宝账号
//+=============================


@property(nonatomic, strong) UIImageView *iv; //背景图片
@property(nonatomic, strong) UILabel *cardNameLabel; //卡片名字
@property(nonatomic, strong) UILabel *cardNumberLabel; // 卡号
@property(nonatomic, strong) UIButton *editButton; // 编辑按钮


@end
@implementation XJWalletZFBView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}




- (void)setupView{
    [self addSubview:self.bgView];
    
    [self.bgView addSubview:self.iv];
    
    [self.iv addSubview:self.cardNameLabel];
    [self.iv addSubview:self.cardNumberLabel];
    [self.iv addSubview:self.editButton];
    
    
    [self.bgView addSubview:self.noDataIv];
    [self.noDataIv addSubview:self.addZfbAccountLb];
}

- (UIView *)bgView {
    if (!_bgView)  {
        _bgView = [UIView new];
    }
    
    return _bgView;
}
// 没有数据的请求
- (UIImageView *)noDataIv {
    if (!_noDataIv) {
        _noDataIv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bj_account_card"]];
        _noDataIv.backgroundColor = [UIColor lightGrayColor];
        _noDataIv.layer.masksToBounds = YES;
        _noDataIv.layer.cornerRadius = 10.0;
        _noDataIv.userInteractionEnabled = YES;
        
        //添加手势
        UITapGestureRecognizer *noDataTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(noDataTapGesAction:)];
        [_noDataIv addGestureRecognizer:noDataTapGes];
    }
    return _noDataIv;
}
- (UILabel *)addZfbAccountLb {
    if (!_addZfbAccountLb) {
        _addZfbAccountLb = [[UILabel alloc] init];
        _addZfbAccountLb.text = @"点击添加支付宝账号";
    }
    return _addZfbAccountLb;
}





- (UIImageView *)iv {
    if (!_iv) {
        _iv = [[UIImageView alloc] init];
        _iv.userInteractionEnabled = YES; // 打开交互
        _iv.image  = [UIImage imageNamed:@"bj_account_card"];
        _iv.backgroundColor = XJCOLOR_RGB(15, 159, 223); //蓝色
        _iv.layer.masksToBounds = YES;
        _iv.layer.cornerRadius = 10;
    }
    return _iv;
}

- (UILabel *)cardNameLabel {
    if (!_cardNumberLabel) {
        _cardNameLabel = [[UILabel alloc] init];
        _cardNameLabel.text = @"支付宝";
        _cardNameLabel.textColor = [UIColor whiteColor];
    }
    return _cardNameLabel;
}


- (UILabel *)cardNumberLabel {
    if (!_cardNumberLabel) {
        _cardNumberLabel = [[UILabel alloc] init];
        _cardNumberLabel.text = @"15837694444";
        _cardNumberLabel.textColor = [UIColor whiteColor];
    }
    return _cardNumberLabel;
}

- (UIButton *)editButton {
    if (!_editButton) {
        _editButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_editButton setTitle:@"编辑" forState:(UIControlStateNormal)];
        _editButton.titleLabel.font = XJFONTSET_R(14.0);
        [_editButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        [_editButton setImage:[UIImage imageNamed:@"address_edit"] forState:(UIControlStateNormal)];
        [_editButton addTarget:self action:@selector(clickEditButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _editButton;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    /**
     iconIv nameLB ......
     ----------------------
     iv
     --------------------------
     bgView
     -------------------------------
    */
    CGFloat k10 = 10;
    CGFloat k60 = ADAPTHeight(60);
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.iv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.bgView);
        make.left.equalTo(self.bgView.mas_left).offset(k10);
        make.right.equalTo(self.bgView.mas_right).offset(-k10);
    }];
    
    // 支付宝
    [self.cardNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iv.mas_left).offset(k60);
        make.centerY.equalTo(self.iv.mas_centerY).offset(-20);
        make.right.equalTo(self.iv.mas_right).offset(-k10);
        make.height.mas_equalTo(20);
    }];
    
    
    // 银行卡号宽度不固定。 15837684444......
    [self.cardNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iv.mas_left).offset(k60);
        make.centerY.equalTo(self.iv.mas_centerY).offset(20);
        make.right.equalTo(self.editButton.mas_left).offset(10);
        make.height.mas_equalTo(20);
    }];
    
    [self.editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cardNameLabel.mas_bottom).offset(15);
        make.right.equalTo(self.iv.mas_right).offset(-k10);
        make.size.mas_equalTo(CGSizeMake(60, 30));
    }];
    
    
    {
        [self.noDataIv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgView.mas_left).offset(k10);
            make.top.bottom.equalTo(self);
            make.right.equalTo(self.bgView.mas_right).offset(-k10);
        }];
        
        [self.addZfbAccountLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.noDataIv.mas_left).offset(k60);
            make.centerY.equalTo(self.noDataIv.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(200, 30));
        }];
    }
}




#pragma makr - 四 赋值
- (void)setZfbModel:(XJWalletTiXianZFBModel *)zfbModel {
    _zfbModel = zfbModel;
    
    
    //判断model是否为空
    if ([NSString isEmptyString:zfbModel.pay_name] || [NSString isEmptyString:zfbModel.customer_name]) {
        
        self.noDataIv.hidden = NO;
        XJLog(@"model为空不做操作");
        return;
    }
    
    
    self.cardNameLabel.text = zfbModel.pay_name;
    self.cardNameLabel.text = zfbModel.customer_name;
    self.noDataIv.hidden = YES;
}


#pragma mark - 点击事件
- (void)clickEditButtonAction:(UIButton *)btn {
    XJLog(@"点击编辑按钮");
    if (self.editButtonBlock) {
        self.editButtonBlock();
    }
}


- (void)noDataTapGesAction:(UITapGestureRecognizer *)tap {
//    XJLog(@"添加支付宝账号");
    if (self.tapNodataIvBlock) {
        self.tapNodataIvBlock();
    }
}



@end
